<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Admin_category_Controller extends CI_Controller{
	
	function __construct(){
		parent::__construct();
		$this->load->model('admin_model');
		$this->load->library('form_validation');
		session_start();
		if($this->uri->segment(2) == 'edit'){
			$this->template->set_template('admin_simple');
		}else{	
			$this->template->set_template('admin');
		}
    }
	
	function index(){
		if(isset($_SESSION['is_admin_logged_in'])){
			$this->html_meta['robots'] = 'nofollow,noindex';
			$this->template->write_view('header', 'admin_header_block', NULL, FALSE);
			$this->template->write_view('content', 'admin_category_block', array('category' => $this->admin_model->get_category_lists()), FALSE);
			$this->render_template = TRUE;
		}else{
			$notLogin = array('notLogin' => TRUE);
			$_SESSION['current_admin_page'] = "category";
			$this->html_meta['robots'] = 'nofollow,noindex';
			$this->template->write_view('header', 'admin_header_block', NULL, FALSE);
			$this->template->write_view('content', 'admin_login_block', $notLogin, FALSE);
			$this->render_template = TRUE;
		}
	}
	
	function edit($id){
		if(isset($_SESSION['is_admin_logged_in'])){
			$this->html_meta['robots'] = 'nofollow,noindex';
			$this->template->write_view('content', 'admin_product_edit', array('category' => $this->admin_model->get_category_by_id($id)), FALSE);
			$this->render_template = TRUE;
		}else{
			$this->template->set_template('admin');
			$notLogin = array('notLogin' => TRUE);
			$_SESSION['current_admin_page'] = "category";
			$this->html_meta['robots'] = 'nofollow,noindex';
			$this->template->write_view('header', 'admin_header_block', NULL, FALSE);
			$this->template->write_view('content', 'admin_login_block', $notLogin, FALSE);
			$this->render_template = TRUE;
		}
	}
	
	function update(){
		if(isset($_SESSION['is_admin_logged_in'])){
			$result = $this->admin_model->update_category_by_id();
			$this->index();
		}else{
			$this->template->set_template('admin');
			$notLogin = array('notLogin' => TRUE);
			$_SESSION['current_admin_page'] = "category";
			$this->html_meta['robots'] = 'nofollow,noindex';
			$this->template->write_view('header', 'admin_header_block', NULL, FALSE);
			$this->template->write_view('content', 'admin_login_block', $notLogin, FALSE);
			$this->render_template = TRUE;
		}
	}
}